package calc;

public class Calc {

    public static Container calculate(float value, Operator operator) {
        Container container = new Container(value, operator, null);
        float result = operator.calculate(container);
        System.out.println(String.format("RESULT IS %f", result));
        return container;
        //return new Container(Math.abs(result), result < 0f ? Operator.SUBTRACT : Operator.ADD, ;
    }

    public static Container calculate(float value, Operator operator, Container prev) {
        Container container = new Container(value, operator, prev);
        float result = operator.calculate(container);
        System.out.println(String.format("RESULT IS %f", result));
        return container;
    }

    // take a chain of containers and produce a final result
    // same as calculate, but only returns a float, thus losing the
    // reference to the chain
    public static float finalize(float value, Operator operator) {
        float result = operator.calculate(new Container(value, operator, null));
        System.out.println(String.format("RESULT IS %f", result));
        return result;
        //return new Container(Math.abs(result), result < 0f ? Operator.SUBTRACT : Operator.ADD, ;
    }

    public static float finalize(float value, Operator operator, Container prev) {
        float result = operator.calculate(new Container(value, operator, prev));
        System.out.println(String.format("RESULT IS %f", result));
        return result;
    }

    // take a chain and calculate its result, without appending any operations
    public static float finalize(Container chain) {
        float result = chain.operator.calculate(chain);
        System.out.println(String.format("RESULT IS %f", result));
        return result;
    }
}
